package com.qf.config;

import com.qf.Constant.RabbitMqConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 你的名字
 * @Date: 2021/07/27/20:30
 * @Description:
 */
@Configuration
public class RabbitMQConfig {

   @Bean
    public TopicExchange orderExchange(){
        return new TopicExchange(RabbitMqConstant.ORDER_EXCHANGE,true,false);
    }
    @Bean
    public TopicExchange dlxExchage(){
      return new TopicExchange(RabbitMqConstant.ORDER_DLX_EXCHANGE,true,false);
    }
    @Bean
    public Queue orderQueue(){
        Map<String,Object>map=new HashMap<>();
        map.put("x-dead-letter-exchange",RabbitMqConstant.ORDER_DLX_EXCHANGE);
        map.put("x-dead-letter-routing-key","de.*");
        map.put("x-message-ttl",1000*10*6);
     return new Queue(RabbitMqConstant.ORDER_QUEUE,true,false,false,map);
    }
    @Bean
    public Queue dlxQueue(){
        return new Queue(RabbitMqConstant.ORDER_DLX_QUEUE,true,false,false);
    }
    @Bean
    public Binding orderBind(){
      return BindingBuilder.bind(orderQueue()).to(orderExchange()).with("order.*");
    }
    @Bean
    public Binding orderDlxBind(){
        return BindingBuilder.bind(dlxQueue()).to(dlxExchage()).with("ode.*");
    }

}
